from Strategy.baseStrategy.grade.strategy20200424 import strategy20200424
from Utility.UpdateBasicData import *
import os
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
os.environ['NUMEXPR_MAX_THREADS'] = '16'
import warnings
import numpy as np
import redis
def saveDataToRedis(data,redis_key):
    redis_client = redis.StrictRedis(host='127.0.0.1')
    modifiedData = data.to_msgpack()
    redis_client.set(redis_key, modifiedData)
    pass
def getDataFromRedis(redis_key):
    redis_client = redis.StrictRedis(host='127.0.0.1')
    data=redis_client.get(redis_key)
    if data!=None:
        data=pd.read_msgpack(data)
    else:
        data=pd.DataFrame()
    return data


#获取股票列表，主要为中证800+额外持仓的股票
filename=os.path.join(LocalFileAddress,'t02_20200422.csv')
mydata=pd.read_csv(filename)
myStocks=mydata[['code','name','price']]
myStocks['hold']=np.round(mydata['hold'],-2)
myStocks=myStocks[myStocks['hold']>=100]
myStocks['marketValue']=myStocks['hold']*myStocks['price']
cash=myStocks['marketValue'].sum()
cash

warnings.filterwarnings('ignore')
logger.info(f'compute start!!!')
#firstDate=20100101
# startDate=20190802
# endDate=20190830
# path1=os.path.join(LocalFileAddress,"sqlserverData")
# path2=r"C:/marketData"
# path3=r"E:/linuxfiles/features"
# check=dataCheck()
# codeList=["600000.SH"]
#check.recordTickDataToTxt(codeList,startDate,endDate,path2)
#check.compareMarketDataFromTxt(codeList,startDate,endDate,path1,path2)
#check.compareFeatureDataFromTxtAndInfluxdb(codeList,startDate,endDate,path3,'MaoTickFactors20190831','MaoTickPredict20190909')


startDate=20200422
endDate=20200422

#myStocks=myStocks.iloc[1:10]
codes=list(myStocks['code'])
#codes=['000063.SZ']
parameters={'targetType':'125mixed',
        'dataPath':r'C:/predictData/strategy20191228',
        'myStocks':myStocks,
        'h5':False,
        'redis':False,
        'influxdb':True,
        'totalCash':cash,
        'predictDatabase':'MaoTickPredict1m2m5m8003weeks',
        'transactionRatio':0.7,
        'maxExposureRatio':0.25,
        'maxVolumeEachTimeRatio':0.25,
        'parameter1':list(0.0001*np.arange(10,80,10)),
        'parameter2':list(0.01*np.arange(10,80,10))
        }
[t,s]=strategy20200424().myParallel(codes,startDate,endDate,parameters)
print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))